/*******************************************************************
 * created by lei.he on 2020/7/27 for entry file
 *******************************************************************/
// 引入 Express 框架
const express = require('express'),
      bodyParser = require('body-parser');
// 实例化
const app = express();

// 引入 util方法 //HeadleLogs
const {HandleLogs} = require('./utils')

// 路径管理
const path = require('path');

//添加中间件
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended : false}))
app.use(express.static(path.join(__dirname,'public'),{index : 'login.html'}))

// 设置端口号 
const SERVER_PORT = 9876;
// 设置监听
app.listen(SERVER_PORT, () => {
    HandleLogs(`service started on port : ${SERVER_PORT}`)
})

// 用户登录，get请求
app.get('/user/login', (req,res) => {
    // console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>get user/login start')
    // console.log(req.query)
    // console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>get user/login end')
    HandleLogs('get user/login',req.query)
    res.send({code:200,message : 'success'})
});

// 用户登录，post请求
app.post('/user/login', (req,res) => {
    // console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>get user/login start')
    // console.log(req.query)
    // console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>get user/login end')
    HandleLogs('post user/login',req.body)
    res.send({code:200,message : 'success'})
});